import {Dimensions, StatusBar, Platform, DeviceInfo, PixelRatio} from 'react-native'
import {Appearance} from 'react-native-appearance'
// iPhoneX Xs
const X_WIDTH = 375;
const X_HEIGHT = 812;

// iPhoneXR XsMax
const XR_WIDTH = 414;
const XR_HEIGHT = 896;

const window = Dimensions.get('window')
const screen = Dimensions.get('screen')

// screen
const SCREEN_WIDTH = Dimensions.get('window').width;
const SCREEN_HEIGHT = Dimensions.get('window').height;


// 字体大小缩放比例
const fontScale = PixelRatio.getFontScale();
// 设备像素密度
const pixelRatio = PixelRatio.get();

export default class ScreenUtils {


    static screenWidth = ScreenUtils.isIos() ? window.width : screen.width
    static screenHeight = ScreenUtils.isIos() ? window.height : screen.height


    // 是否为iphonex
    static isIphoneX() {
        let isIphoneX = false
        if (ScreenUtils.isIos()) {
            if ((SCREEN_WIDTH === X_WIDTH && SCREEN_HEIGHT === X_HEIGHT) || (SCREEN_WIDTH === XR_WIDTH && SCREEN_HEIGHT === XR_HEIGHT)) {
                isIphoneX = true
            }
        }
        return isIphoneX
    }

    // 字体适配
    static setFont(fontSize) {

        // return (
        //     // fontSize * (1.0 / DeviceInfo.Dimensions.screenPhysicalPixels.fontScale)
        //
        // );
        let size = fontSize * (2 / fontScale)
        return size / pixelRatio
    }

    static isIos() {
        return Platform.OS !== 'android';
    }

    static isDarkTheme () {
        return Appearance.getColorScheme() === 'dark'
    }
}

// export const screenUtils = new ScreenUtils();
